package com.codeczx.recyclerviewdemo.swipe;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.codeczx.recyclerviewdemo.R;

import java.util.Collections;
import java.util.List;

/**
 * Created by codeczx on 2017/9/5.
 */

public class SwipeAdapter extends RecyclerView.Adapter<SwipeAdapter.NormalViewHolder> implements ItemTouchHelperAdapter{

    private List<String> mList;

    public SwipeAdapter(List<String> list) {
        mList = list;
    }

    @Override
    public NormalViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_rv_swipe_left,parent,false);
        return new NormalViewHolder(itemView);
    }

    @Override
    public void onBindViewHolder(NormalViewHolder holder, int position) {
        holder.tvItem.setText(mList.get(position));
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    @Override
    public void onItemMove(int fromPosition, int toPosition) {
        Collections.swap(mList,fromPosition,toPosition);
        notifyItemMoved(fromPosition,toPosition);
    }

    @Override
    public void onItemDismiss(int position) {
//        mList.remove(position);
//        notifyItemRemoved(position);
    }

    public class NormalViewHolder extends RecyclerView.ViewHolder {

        TextView tvItem;
        TextView tvText;

        public NormalViewHolder(View itemView) {
            super(itemView);
            tvItem = (TextView) itemView.findViewById(R.id.tv_item);
            tvText = (TextView) itemView.findViewById(R.id.tv_text);
        }
    }
}
